package com.colorful.insuranceproject.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.colorful.insuranceproject.R;
import com.colorful.insuranceproject.bean.UploadRecordBean;
import com.colorful.insuranceproject.consts.ClaimsStatus;
import com.lovely3x.common.adapter.BaseViewHolder;
import com.lovely3x.common.adapter.ListAdapter;

import java.util.List;

import butterknife.Bind;

/**
 * Created by handsome-Bob on 2017/8/18.
 * <p>
 * 上传记录的适配器
 */
public class UploadRecordAdapter extends ListAdapter<UploadRecordBean> {

    public UploadRecordAdapter(List<UploadRecordBean> datas, Context context) {
        super(datas, context);
    }

    @NonNull
    @Override
    public BaseViewHolder createViewHolder(int position, ViewGroup parent) {
        return new ViewHolder(getLayoutInflater().inflate(R.layout.item_upload_record, parent, false));
    }

    @Override
    public void handleData(final int position, @NonNull BaseViewHolder holder) {
        ViewHolder viewHolder = (ViewHolder) holder;
        UploadRecordBean bean = datas.get(position);

        viewHolder.tvOrderNum.setText(bean.getInsuranceNo());//理赔单号
        viewHolder.tvClaimsPerson.setText(bean.getInsuranceMoney());//理赔金额
        viewHolder.tvClaimsTime.setText(bean.getIncomeSrc() == 0 ? "扫码直赔" : (bean.getIncomeSrc() == 1 ? "票据理赔" : "在线直赔"));//理赔类型
//        incomeSrc   // 来源  0扫码直赔 1票据上传  2杭州九州大药房 3宁波九州大药房 4九州H5    也就是 0是扫码直赔 1是票据理赔  4 在线直赔
        viewHolder.tvClaimsStatus.setText(ClaimsStatus.judgeCaimsSatus(bean.getInsuranceStatus()));//理赔状态


        final View.OnClickListener onClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mViewClickedListener != null) {
                    mViewClickedListener.onViewClicked(position, v);
                }
            }
        };
        viewHolder.tvOperationOne.setOnClickListener(onClickListener);
        viewHolder.tvOperationTwo.setOnClickListener(onClickListener);
        viewHolder.tvOrderNum.setOnClickListener(onClickListener);


        if (bean.getInsuranceStatus() == 1) {//电子票据审核中
            viewHolder.tvOperationOne.setVisibility(View.VISIBLE);
            viewHolder.tvOperationTwo.setVisibility(View.VISIBLE);
            viewHolder.tvOperationOne.setText("补充");
        } else if (bean.getInsuranceStatus() == 3) {//电子票据审核失败
            viewHolder.tvOperationOne.setVisibility(View.VISIBLE);
            viewHolder.tvOperationTwo.setVisibility(View.GONE);
            viewHolder.tvOperationOne.setText("编辑");
        } else {
            viewHolder.tvOperationOne.setVisibility(View.VISIBLE);
            viewHolder.tvOperationTwo.setVisibility(View.GONE);
            viewHolder.tvOperationOne.setText("--");
        }


        viewHolder.viewLine.setVisibility(position == getCount() - 1 ? View.GONE : View.VISIBLE);
    }

    class ViewHolder extends BaseViewHolder {

        @Bind(R.id.tv_order_num)
        TextView tvOrderNum;

        @Bind(R.id.tv_claims_person)
        TextView tvClaimsPerson;

        @Bind(R.id.tv_claims_time)
        TextView tvClaimsTime;

        @Bind(R.id.tv_claims_status)
        TextView tvClaimsStatus;

        @Bind(R.id.tv_operation_one)
        TextView tvOperationOne;

        @Bind(R.id.tv_operation_two)
        TextView tvOperationTwo;

        @Bind(R.id.view_line)
        View viewLine;


        public ViewHolder(View rootView) {
            super(rootView);
        }
    }
}
